package com.bst.bsj.bops.web.biz.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bst.bsj.bops.web.biz.SeedlingService;
import com.bst.bsj.common.dal.daointerface.SeedlingDAO;
import com.bst.bsj.common.dal.dataobject.Seedling;
import com.homewaimai.common.lang.Paginator;
import com.homewaimai.common.lang.Result;
import com.homewaimai.common.lang.ResultSupport;

@Service("seedlingService")
public class SeedlingServiceImpl implements SeedlingService {

  private static final Log logger = LogFactory.getLog(SeedlingServiceImpl.class);

  @Autowired
  private SeedlingDAO seedlingDAO;

  @Override
  public Result query(Map paramMap) {
    Result result = new ResultSupport(false);

    Long offset = (Long) paramMap.get("offset");
    Long length = (Long) paramMap.get("length");
    Integer page = (Integer) paramMap.get("page");
    Long total = seedlingDAO.getCounts(paramMap);
    List<Seedling> seedlingList = seedlingDAO.selectAll(paramMap, offset, length);

    // 创建一个分页器(leng.intValue：每页多少条)
    Paginator paginator = new Paginator(length.intValue());
    // 设置总项数
    paginator.setItems(total == null ? 0 : total.intValue());
    // 设置当前页
    paginator.setPage(page);
    result.getModels().put("paginator", paginator);
    result.getModels().put("seedlingList", seedlingList);

    result.setSuccess(true);
    return result;
  }

  @Override
  public Seedling getSeedling(Long id) {
    return seedlingDAO.getSeedling(id);
  }

  @Override
  public int update(Seedling seedling) {
    int lid = 0;
    try {

      lid = seedlingDAO.update(seedling);
    } catch (Exception e) {
      logger.error("SeedlingServiceImpl.update(banner) error!", e);
    }
    return lid;
    
  }

  @Override
  public Result queryHots(Map<String, Object> paramsMap) {
    Result result = new ResultSupport(false);

    Long length = (Long) paramsMap.get("length");
    Integer page = (Integer) paramsMap.get("page");
    Long total = seedlingDAO.getCounts(paramsMap);
    List<Seedling> seedlingList = seedlingDAO.selectAllHots(paramsMap);

    // 创建一个分页器(leng.intValue：每页多少条)
    Paginator paginator = new Paginator(length.intValue());
    // 设置总项数
    paginator.setItems(total == null ? 0 : total.intValue());
    // 设置当前页
    paginator.setPage(page);
    result.getModels().put("paginator", paginator);
    result.getModels().put("seedlingList", seedlingList);

    result.setSuccess(true);
    return result;
  }
  
  @Override
  public int updateSort(Map<String, Object> params) {
    return seedlingDAO.updateSort(params);
  }

  @Override
  public Long getMaxSeq() {
    return seedlingDAO.getMaxSeq();
  }

  @Override
  public List<Map<String, Object>> getCategory(Map<String, Object> paramsMap) {
   
    return seedlingDAO.getCategory(paramsMap);
  }

  @Override
  public List<Map<String, Object>> getSeedlingType(Map<String, Object> paramsMap) {
    
    return seedlingDAO.getSeedlingType(paramsMap);
  }

  @Override
  public Long getCounts(Map<String, Object> paramMap) {
    return seedlingDAO.getCounts(paramMap);
  }

  @Override
  public List<Seedling> queryOrderById(Map<String, Object> paramMap) {
    return seedlingDAO.queryOrderById(paramMap);
  }

  @Override
  public int soldTimeUpdate(List<Long> idList) {
    return seedlingDAO.soldTimeUpdate(idList);
  }

  @Override
  public Long getOnSaleCount(Map<String, Object> paramMap) {
    
    return seedlingDAO.getOnSaleCount(paramMap);
  }

  @Override
  public List<Seedling> getAfterHots(Map<String, Object> params) {
    return  seedlingDAO.getAfterHots(params);
  }

  @Override
  public void deleteByParams(Map<String, Object> paramsMap) {
    seedlingDAO.deleteByParams(paramsMap);
    
  }

}
